//
//  NameViewController.m
//  UI10_HomeWork
//
//  Created by Bodi on 16/6/17.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "NameViewController.h"
#import "BodiView.h"
@interface NameViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (nonatomic, retain)UIButton *button;
@property (nonatomic, retain)NSArray *labelTextArray;
@property (nonatomic, retain)NSArray<UITextField *> *textFieldArray;
@property (nonatomic, retain)NSArray *changeArray;

@end

@implementation NameViewController
- (void)dealloc{
    [_labelTextArray release];
    [_textFieldArray release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"name";
    [self holdAllData];
    [self createButton];
    [self createBodiView];
}
- (void)holdAllData{
    
    self.array = [[NSMutableArray alloc]init];
    
    NSArray *labelArray = @[@"姓名", @"电话", @"QQ"];
    NSArray *textFieldArray = @[@"name", @"number", @"QQnumber"];
    NSArray *changeArray = @[self.strName,self.strNumber,self.strQq];
    self.labelTextArray = labelArray;
    self.textFieldArray = textFieldArray;
    self.changeArray = changeArray;

}
- (void)createButton{
    NSString *str = self.strImage;
    UIImage *image = [UIImage imageNamed:str];
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.button setImage:image forState:UIControlStateNormal];
    self.button.frame = CGRectMake(150, 150, 100, 100);
    self.button.layer.cornerRadius = 50;
    self.button.layer.masksToBounds = YES;
    [self.view addSubview:self.button];
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"联系人.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];


}
- (void)leftAction:(UIButton *)button{
[self.navigationController popViewControllerAnimated:YES];
//    self.delegate = self;
    [self.delegate change:self.array[0].textField.text];
    
//    NSLog(@"%ld", self.array.count);
//    NSLog(@"%@",self.array[0].textField.text);
//    NSLog(@"%@",self.textFieldArray[0].text);

}

- (void)buttonAction:(UIButton *)button{
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    
    //允许用户编辑
    
    picker.allowsEditing = YES;
    picker.delegate = self;
    [self presentViewController:picker animated:YES completion:^{
        
        
    }];
    
    
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    
    NSLog(@"%@", info);
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [self.button setImage:image forState:UIControlStateNormal];
    
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}

//- (void)creatSubView{
//   BodiView *view = [[BodiView alloc]initWithFrame:CGRectMake(20, 300, 300, 200) withLabelText:@"姓名" withPlaceholder:@"name"];
//    
//    [self.view addSubview:view];
//
//}

- (void)createBodiView{
    for (int i = 0; i < 3; i++) {
        BodiView *view = [[BodiView alloc]initWithFrame:CGRectMake(30, 300 + 60 * i, 260, 50) withLabelText:self.labelTextArray[i] withPlaceholder:self.changeArray[i]];
        [self.view addSubview:view];
        [view release];
        [self.array addObject:view];
//        if (i == 0) {
//            self.str = view.textField.text;
//        }
    }
    

}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
